/*******************************************************************************
** Copyright (c) 2003 MaK Technologies, Inc.
** All rights reserved.
*******************************************************************************/
/*******************************************************************************
** $RCSfile: logicalTimeImpl.h,v $ $Revision: 1.13 $ $State: Exp $
*******************************************************************************/

#ifndef RTI_LogicalTimeImpl_H_
#define RTI_LogicalTimeImpl_H_

#include <RTI/LogicalTime.h>
#include "logicalTimeIntervalImpl.h"

// Depreciated: Use specific implementation
class RTI_EXPORT_FEDTIME LogicalTimeImpl : public rti1516::LogicalTime
{
public:
   // Constructors
   LogicalTimeImpl();
   LogicalTimeImpl(double const & value);
   LogicalTimeImpl(rti1516::LogicalTime const & value);
   LogicalTimeImpl(LogicalTimeImpl const & value);

   // Destructor
   virtual ~LogicalTimeImpl()
   throw ();

   // Basic accessors/mutators
   virtual void setInitial();
   virtual bool isInitial() const;

   virtual void setFinal();
   virtual bool isFinal() const;

   // Assignment
   virtual rti1516::LogicalTime& operator= (rti1516::LogicalTime const & value)
      throw (
         rti1516::InvalidLogicalTime);

   virtual
   rti1516::LogicalTime&
   operator+= (rti1516::LogicalTimeInterval const & addend)
      throw (
         rti1516::IllegalTimeArithmetic,
         rti1516::InvalidLogicalTimeInterval);

   virtual
   rti1516::LogicalTime&
   operator-= (rti1516::LogicalTimeInterval const & subtrahend)
      throw (
         rti1516::IllegalTimeArithmetic,
         rti1516::InvalidLogicalTimeInterval);

   virtual
   bool
   operator> (rti1516::LogicalTime const & value) const
      throw (
         rti1516::InvalidLogicalTime);

   virtual
   bool
   operator< (rti1516::LogicalTime const & value) const
      throw (
         rti1516::InvalidLogicalTime);

   virtual
   bool
   operator== (rti1516::LogicalTime const & value) const
      throw (
         rti1516::InvalidLogicalTime);

   virtual
   bool
   operator>= (rti1516::LogicalTime const & value) const
      throw (
         rti1516::InvalidLogicalTime);

   virtual
   bool
   operator<= (rti1516::LogicalTime const & value) const
      throw (
         rti1516::InvalidLogicalTime);

   // Generates an encoded value that can be used to send
   // LogicalTimes to other federates in updates or interactions
   virtual rti1516::VariableLengthData encode() const;

   // Alternate encode for directly filling a buffer
   virtual unsigned long encodedLength() const;
   virtual unsigned long encode(void* buffer, unsigned long bufferSize) const
       throw (rti1516::CouldNotEncode);

   // Decode VariableLengthData into self
   virtual void decode(rti1516::VariableLengthData const & VariableLengthData)
      throw (
         rti1516::InternalError,
         rti1516::CouldNotDecode);

   // Alternate decode that reads directly from a buffer
   virtual void decode(void* buffer, unsigned long bufferSize)
      throw (
         rti1516::InternalError,
         rti1516::CouldNotDecode);

   virtual std::wstring toString() const;

   // Returns the name of the implementation, as needed by
   // createFederationExecution.
   virtual std::wstring implementationName() const;

public:
   //-----------------------------------------------------------------
   // Implementation functions
   //-----------------------------------------------------------------
   virtual double getTime() const;

   //-----------------------------------------------------------------
   // Implementation operators
   //-----------------------------------------------------------------
   virtual LogicalTimeImpl& operator= (const LogicalTimeImpl&)
   throw (rti1516::InvalidLogicalTime);

   virtual rti1516::LogicalTime& operator= (double const & value)
   throw (rti1516::InvalidLogicalTime);

   virtual rti1516::LogicalTime& operator+= (double const & value)
   throw (rti1516::InvalidLogicalTime);

   virtual rti1516::LogicalTime& operator-= (double const & value)
   throw (rti1516::InvalidLogicalTime);

   virtual bool operator== (double const & value) const
   throw (rti1516::InvalidLogicalTime);

   virtual bool operator!= (double const & value) const
   throw (rti1516::InvalidLogicalTime);

   virtual bool operator!= (rti1516::LogicalTime const & value) const
   throw (rti1516::InvalidLogicalTime);

   virtual bool operator> (double const & value) const
      throw (rti1516::InvalidLogicalTime);

   virtual bool operator< (double const & value) const
      throw (rti1516::InvalidLogicalTime);

   virtual bool operator>= (double const & value) const
      throw (rti1516::InvalidLogicalTime);

   virtual bool operator<= (double const & value) const
      throw (rti1516::InvalidLogicalTime);

   private:

   friend class LogicalTimeIntervalImpl;

   //-----------------------------------------------------------------
   // Implementation member variables
   //-----------------------------------------------------------------
   double myLogicalTime;
   double myZero;
   double myEpsilon;
   double myPositiveInfinity;
};

#endif // RTI_LogicalTimeImpl_H_
